package com.cloudlead.plugin.scheduler.vo;

import java.util.List;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import com.cloudlead.plugin.scheduler.action.validator.ScheduleJobValidatorGroup;
import com.cloudlead.plugin.scheduler.vo.dict.ExecType;
import com.cloudlead.plugin.scheduler.vo.dict.JobStatus;
import com.cloudlead.common.lang.annotation.Domain;
import com.cloudlead.common.lang.annotation.HasManys;
import com.cloudlead.common.lang.annotation.Label;
import com.cloudlead.common.lang.annotation.Unique;
import com.cloudlead.common.lang.persistence.AbstractIdEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * ScheduleJob is a Codegen vo type
 */
@Label("计划任务")
@Unique("name")
@HasManys(values = {@com.cloudlead.common.lang.annotation.HasMany(property = "scheduleJobParamss", associatedField = "jobId")})
@Domain(domainClassName = "com.cloudlead.plugin.scheduler.entity.EScheduleJob")
public class ScheduleJob extends AbstractIdEntity<String> {

    private static final long serialVersionUID = 286753258621196L;
    @Label("调度表达式")
    @Size(max = 255)
    private String cron;

    @Label("完成时间")
    private Long endTime;

    @Label("执行内容")
    @Size(max = 65535)
    @NotNull(groups = {ScheduleJobValidatorGroup.Create.class, ScheduleJobValidatorGroup.Update.class})
    private String exec;

    @Label("执行类型")
    @NotNull(groups = {ScheduleJobValidatorGroup.Create.class, ScheduleJobValidatorGroup.Update.class})
    private ExecType execType;

    @Label("编号")
    @Size(max = 24)
    @NotNull(groups = {ScheduleJobValidatorGroup.Update.class})
    private String id;

    @Label("工作任务名称")
    @Size(max = 255)
    @NotNull(groups = {ScheduleJobValidatorGroup.Create.class, ScheduleJobValidatorGroup.Update.class})
    private String name;

    @Label("开始时间")
    private Long startTime;

    @Label("任务状态")
    private JobStatus status;

    @Label("用户")
    @Size(max = 255)
    private String username;

    @Label("计划任务参数列表")
    @JsonIgnore
    private List<ScheduleJobParams> scheduleJobParamss;

    public String getCron() {
        return cron;
    }

    public void setCron(String cron) {
        this.cron = cron;
    }

    public Long getEndTime() {
        return endTime;
    }

    public void setEndTime(Long endTime) {
        this.endTime = endTime;
    }

    public String getExec() {
        return exec;
    }

    public void setExec(String exec) {
        this.exec = exec;
    }

    public ExecType getExecType() {
        return execType;
    }

    public void setExecType(ExecType execType) {
        this.execType = execType;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<ScheduleJobParams> getScheduleJobParamss() {
        return scheduleJobParamss;
    }

    public void setScheduleJobParamss(List<ScheduleJobParams> scheduleJobParamss) {
        this.scheduleJobParamss = scheduleJobParamss;
    }

    public Long getStartTime() {
        return startTime;
    }

    public void setStartTime(Long startTime) {
        this.startTime = startTime;
    }

    public JobStatus getStatus() {
        return status;
    }

    public void setStatus(JobStatus status) {
        this.status = status;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String toString() {
        return String
                .format("ScheduleJob { cron : %s,endTime : %s,exec : %s,execType : %s,id : %s,name : %s,scheduleJobParamss : %s,startTime : %s,status : %s,username : %s }",
                        cron, endTime, exec, execType, id, name,
                        scheduleJobParamss, startTime, status, username);
    }

}
